import {GETMENULIST, GETMENUINFO, SAVEMENU, UPDATEMENU, ROUTES, MENUSELECT, DELETEMENU} from '@/services/api'
import {request, METHOD, removeAuthorization} from '@/utils/request'

/**
 * 菜单列表
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function getMenuList() {
  return request(GETMENULIST, METHOD.GET);
}
/**
 * 获取菜单
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function getRoutesConfig() {
  return request(ROUTES, METHOD.GET);
}

/**
 * 菜单树形数据
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function menuSelect() {
  return request(MENUSELECT, METHOD.GET);
}

/**
 * 新增菜单
 * @param menuName 菜单名称
 * @param supMenu 邮箱
 * @param path 手机号码
 * @param icon 状态
 * @param router 注册名
 * @param invisible 是否隐藏 0否1是
 * @param sort 排序
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function saveMenu(menuName,supMenu,path,icon,router,invisible,sort) {
  return request(SAVEMENU, METHOD.POST,{
    name: menuName,
    pid: supMenu,
    path: path,
    icon: icon,
    router: router,
    sort: sort,
    invisible: invisible,
  });
}

/**
 * 新增菜单
 * @param id 菜单id
 * @param menuName 菜单名称
 * @param supMenu 邮箱
 * @param path 手机号码
 * @param icon 状态
 * @param router 注册名
 * @param invisible 是否隐藏 0否1是
 * @param sort 排序
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function updateMenu(id,menuName,supMenu,path,icon,router,invisible,sort) {
  return request(UPDATEMENU, METHOD.POST,{
    id: id,
    name: menuName,
    pid: supMenu,
    path: path,
    icon: icon,
    router: router,
    sort: sort,
    invisible: invisible,
  });
}
/**
 * 删除菜单
 * @param id 菜单id
 * @returns {Promise<AxiosResponse<T>>}
 */
export async function deleteMenu(id) {
  return request(DELETEMENU, METHOD.POST, {
    ids: id
  })
}
export default {
  saveMenu,
  getMenuList,
  menuSelect,
  updateMenu,
  deleteMenu,
  getRoutesConfig
}
